<?php

/**
 * BankAccount.
 *
 * PHP version 8.3
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */

/**
 * The Selling Partner API for Amazon Seller Wallet Open Banking API.
 *
 * The Selling Partner API for Seller Wallet (Seller Wallet API) provides financial information that is relevant to a seller's Seller Wallet account. You can obtain financial events, balances, and transfer schedules for Seller Wallet accounts. You can also schedule and initiate transactions.
 *
 * The version of the OpenAPI document: 2024-03-01
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.9.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace SpApi\Model\sellerWallet\v2024_03_01;

use SpApi\Model\ModelInterface;
use SpApi\ObjectSerializer;

/**
 * BankAccount Class Doc Comment.
 *
 * @category Class
 *
 * @description Details of an Amazon SW bank account, used to hold money earned by a SW customer by selling items. NOTE: Not including account_links, short cut links to the account balance and transactions -&gt; since not mandatory
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 *
 * @implements \ArrayAccess<string, mixed>
 */
class BankAccount implements ModelInterface, \ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

    /**
     * The original name of the model.
     */
    protected static string $openAPIModelName = 'BankAccount';

    /**
     * Array of property to type mappings. Used for (de)serialization.
     *
     * @var string[]
     */
    protected static array $openAPITypes = [
        'account_id' => 'string',
        'account_holder_name' => 'string',
        'bank_account_number_format' => '\SpApi\Model\sellerWallet\v2024_03_01\BankAccountNumberFormat',
        'bank_name' => 'string',
        'bank_account_ownership_type' => '\SpApi\Model\sellerWallet\v2024_03_01\BankAccountOwnershipType',
        'routing_number' => 'string',
        'bank_number_format' => '\SpApi\Model\sellerWallet\v2024_03_01\BankNumberFormat',
        'account_country_code' => 'string',
        'account_currency' => 'string',
        'bank_account_number_tail' => 'string',
        'bank_account_holder_status' => '\SpApi\Model\sellerWallet\v2024_03_01\BankAccountHolderStatus'];

    /**
     * Array of property to format mappings. Used for (de)serialization.
     *
     * @var string[]
     *
     * @phpstan-var array<string, string|null>
     *
     * @psalm-var array<string, string|null>
     */
    protected static array $openAPIFormats = [
        'account_id' => null,
        'account_holder_name' => null,
        'bank_account_number_format' => null,
        'bank_name' => null,
        'bank_account_ownership_type' => null,
        'routing_number' => null,
        'bank_number_format' => null,
        'account_country_code' => null,
        'account_currency' => null,
        'bank_account_number_tail' => null,
        'bank_account_holder_status' => null];

    /**
     * Array of nullable properties. Used for (de)serialization.
     *
     * @var bool[]
     */
    protected static array $openAPINullables = [
        'account_id' => true,
        'account_holder_name' => false,
        'bank_account_number_format' => false,
        'bank_name' => true,
        'bank_account_ownership_type' => false,
        'routing_number' => false,
        'bank_number_format' => false,
        'account_country_code' => false,
        'account_currency' => false,
        'bank_account_number_tail' => false,
        'bank_account_holder_status' => true,
    ];

    /**
     * If a nullable field gets set to null, insert it here.
     *
     * @var bool[]
     */
    protected array $openAPINullablesSetToNull = [];

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     *
     * @var string[]
     */
    protected static array $attributeMap = [
        'account_id' => 'accountId',
        'account_holder_name' => 'accountHolderName',
        'bank_account_number_format' => 'bankAccountNumberFormat',
        'bank_name' => 'bankName',
        'bank_account_ownership_type' => 'bankAccountOwnershipType',
        'routing_number' => 'routingNumber',
        'bank_number_format' => 'bankNumberFormat',
        'account_country_code' => 'accountCountryCode',
        'account_currency' => 'accountCurrency',
        'bank_account_number_tail' => 'bankAccountNumberTail',
        'bank_account_holder_status' => 'bankAccountHolderStatus',
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     *
     * @var string[]
     */
    protected static array $setters = [
        'account_id' => 'setAccountId',
        'account_holder_name' => 'setAccountHolderName',
        'bank_account_number_format' => 'setBankAccountNumberFormat',
        'bank_name' => 'setBankName',
        'bank_account_ownership_type' => 'setBankAccountOwnershipType',
        'routing_number' => 'setRoutingNumber',
        'bank_number_format' => 'setBankNumberFormat',
        'account_country_code' => 'setAccountCountryCode',
        'account_currency' => 'setAccountCurrency',
        'bank_account_number_tail' => 'setBankAccountNumberTail',
        'bank_account_holder_status' => 'setBankAccountHolderStatus',
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests).
     *
     * @var string[]
     */
    protected static array $getters = [
        'account_id' => 'getAccountId',
        'account_holder_name' => 'getAccountHolderName',
        'bank_account_number_format' => 'getBankAccountNumberFormat',
        'bank_name' => 'getBankName',
        'bank_account_ownership_type' => 'getBankAccountOwnershipType',
        'routing_number' => 'getRoutingNumber',
        'bank_number_format' => 'getBankNumberFormat',
        'account_country_code' => 'getAccountCountryCode',
        'account_currency' => 'getAccountCurrency',
        'bank_account_number_tail' => 'getBankAccountNumberTail',
        'bank_account_holder_status' => 'getBankAccountHolderStatus',
    ];

    /**
     * Associative array for storing property values.
     */
    protected array $container = [];

    /**
     * Constructor.
     *
     * @param null|array $data Associated array of property values
     *                         initializing the model
     */
    public function __construct(?array $data = null)
    {
        $this->setIfExists('account_id', $data ?? [], null);
        $this->setIfExists('account_holder_name', $data ?? [], null);
        $this->setIfExists('bank_account_number_format', $data ?? [], null);
        $this->setIfExists('bank_name', $data ?? [], null);
        $this->setIfExists('bank_account_ownership_type', $data ?? [], null);
        $this->setIfExists('routing_number', $data ?? [], null);
        $this->setIfExists('bank_number_format', $data ?? [], null);
        $this->setIfExists('account_country_code', $data ?? [], null);
        $this->setIfExists('account_currency', $data ?? [], null);
        $this->setIfExists('bank_account_number_tail', $data ?? [], null);
        $this->setIfExists('bank_account_holder_status', $data ?? [], null);
    }

    /**
     * Gets the string presentation of the object.
     *
     * @return string
     */
    public function __toString()
    {
        return json_encode(
            ObjectSerializer::sanitizeForSerialization($this),
            JSON_PRETTY_PRINT
        );
    }

    /**
     * Array of property to type mappings. Used for (de)serialization.
     */
    public static function openAPITypes(): array
    {
        return self::$openAPITypes;
    }

    /**
     * Array of property to format mappings. Used for (de)serialization.
     */
    public static function openAPIFormats(): array
    {
        return self::$openAPIFormats;
    }

    /**
     * Checks if a property is nullable.
     */
    public static function isNullable(string $property): bool
    {
        return self::openAPINullables()[$property] ?? false;
    }

    /**
     * Checks if a nullable property is set to null.
     */
    public function isNullableSetToNull(string $property): bool
    {
        return in_array($property, $this->getOpenAPINullablesSetToNull(), true);
    }

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     */
    public static function attributeMap(): array
    {
        return self::$attributeMap;
    }

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     */
    public static function setters(): array
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests).
     */
    public static function getters(): array
    {
        return self::$getters;
    }

    /**
     * The original name of the model.
     */
    public function getModelName(): string
    {
        return self::$openAPIModelName;
    }

    /**
     * Show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties(): array
    {
        $invalidProperties = [];

        if (null === $this->container['account_holder_name']) {
            $invalidProperties[] = "'account_holder_name' can't be null";
        }
        if (null === $this->container['bank_account_number_format']) {
            $invalidProperties[] = "'bank_account_number_format' can't be null";
        }
        if (null === $this->container['bank_account_ownership_type']) {
            $invalidProperties[] = "'bank_account_ownership_type' can't be null";
        }
        if (null === $this->container['routing_number']) {
            $invalidProperties[] = "'routing_number' can't be null";
        }
        if (null === $this->container['bank_number_format']) {
            $invalidProperties[] = "'bank_number_format' can't be null";
        }
        if (null === $this->container['account_country_code']) {
            $invalidProperties[] = "'account_country_code' can't be null";
        }
        if (null === $this->container['account_currency']) {
            $invalidProperties[] = "'account_currency' can't be null";
        }
        if (null === $this->container['bank_account_number_tail']) {
            $invalidProperties[] = "'bank_account_number_tail' can't be null";
        }

        return $invalidProperties;
    }

    /**
     * Validate all the properties in the model
     * return true if all passed.
     *
     * @return bool True if all properties are valid
     */
    public function valid(): bool
    {
        return 0 === count($this->listInvalidProperties());
    }

    /**
     * Gets account_id.
     */
    public function getAccountId(): ?string
    {
        return $this->container['account_id'];
    }

    /**
     * Sets account_id.
     *
     * @param null|string $account_id The unique identifier provided by Amazon to identify the account
     */
    public function setAccountId(?string $account_id): self
    {
        if (is_null($account_id)) {
            array_push($this->openAPINullablesSetToNull, 'account_id');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('account_id', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['account_id'] = $account_id;

        return $this;
    }

    /**
     * Gets account_holder_name.
     */
    public function getAccountHolderName(): string
    {
        return $this->container['account_holder_name'];
    }

    /**
     * Sets account_holder_name.
     *
     * @param string $account_holder_name BankAccount holder's name (expected to be Amazon customer)
     */
    public function setAccountHolderName(string $account_holder_name): self
    {
        if (is_null($account_holder_name)) {
            throw new \InvalidArgumentException('non-nullable account_holder_name cannot be null');
        }
        $this->container['account_holder_name'] = $account_holder_name;

        return $this;
    }

    /**
     * Gets bank_account_number_format.
     */
    public function getBankAccountNumberFormat(): string
    {
        return $this->container['bank_account_number_format'];
    }

    /**
     * Sets bank_account_number_format.
     *
     * @param string $bank_account_number_format bank_account_number_format
     */
    public function setBankAccountNumberFormat(string $bank_account_number_format): self
    {
        if (is_null($bank_account_number_format)) {
            throw new \InvalidArgumentException('non-nullable bank_account_number_format cannot be null');
        }
        $this->container['bank_account_number_format'] = $bank_account_number_format;

        return $this;
    }

    /**
     * Gets bank_name.
     */
    public function getBankName(): ?string
    {
        return $this->container['bank_name'];
    }

    /**
     * Sets bank_name.
     *
     * @param null|string $bank_name The name of the bank, for all Amazon Seller Wallet account the value will be Amazon Seller Wallet
     */
    public function setBankName(?string $bank_name): self
    {
        if (is_null($bank_name)) {
            array_push($this->openAPINullablesSetToNull, 'bank_name');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('bank_name', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['bank_name'] = $bank_name;

        return $this;
    }

    /**
     * Gets bank_account_ownership_type.
     */
    public function getBankAccountOwnershipType(): string
    {
        return $this->container['bank_account_ownership_type'];
    }

    /**
     * Sets bank_account_ownership_type.
     *
     * @param string $bank_account_ownership_type bank_account_ownership_type
     */
    public function setBankAccountOwnershipType(string $bank_account_ownership_type): self
    {
        if (is_null($bank_account_ownership_type)) {
            throw new \InvalidArgumentException('non-nullable bank_account_ownership_type cannot be null');
        }
        $this->container['bank_account_ownership_type'] = $bank_account_ownership_type;

        return $this;
    }

    /**
     * Gets routing_number.
     */
    public function getRoutingNumber(): string
    {
        return $this->container['routing_number'];
    }

    /**
     * Sets routing_number.
     *
     * @param string $routing_number Routing number for automated clearing house transfers, for all Amazon Seller Wallet account the value will be denoted by nine cosecutive 0's,
     */
    public function setRoutingNumber(string $routing_number): self
    {
        if (is_null($routing_number)) {
            throw new \InvalidArgumentException('non-nullable routing_number cannot be null');
        }
        $this->container['routing_number'] = $routing_number;

        return $this;
    }

    /**
     * Gets bank_number_format.
     */
    public function getBankNumberFormat(): string
    {
        return $this->container['bank_number_format'];
    }

    /**
     * Sets bank_number_format.
     *
     * @param string $bank_number_format bank_number_format
     */
    public function setBankNumberFormat(string $bank_number_format): self
    {
        if (is_null($bank_number_format)) {
            throw new \InvalidArgumentException('non-nullable bank_number_format cannot be null');
        }
        $this->container['bank_number_format'] = $bank_number_format;

        return $this;
    }

    /**
     * Gets account_country_code.
     */
    public function getAccountCountryCode(): string
    {
        return $this->container['account_country_code'];
    }

    /**
     * Sets account_country_code.
     *
     * @param string $account_country_code the two digit country code, in ISO 3166 format
     */
    public function setAccountCountryCode(string $account_country_code): self
    {
        if (is_null($account_country_code)) {
            throw new \InvalidArgumentException('non-nullable account_country_code cannot be null');
        }
        $this->container['account_country_code'] = $account_country_code;

        return $this;
    }

    /**
     * Gets account_currency.
     */
    public function getAccountCurrency(): string
    {
        return $this->container['account_currency'];
    }

    /**
     * Sets account_currency.
     *
     * @param string $account_currency BankAccount currency code in ISO 4217 format
     */
    public function setAccountCurrency(string $account_currency): self
    {
        if (is_null($account_currency)) {
            throw new \InvalidArgumentException('non-nullable account_currency cannot be null');
        }
        $this->container['account_currency'] = $account_currency;

        return $this;
    }

    /**
     * Gets bank_account_number_tail.
     */
    public function getBankAccountNumberTail(): string
    {
        return $this->container['bank_account_number_tail'];
    }

    /**
     * Sets bank_account_number_tail.
     *
     * @param string $bank_account_number_tail Last 3 digit of the bank account number, for all Amazon Seller Wallet account the value will be three consecutive 0's
     */
    public function setBankAccountNumberTail(string $bank_account_number_tail): self
    {
        if (is_null($bank_account_number_tail)) {
            throw new \InvalidArgumentException('non-nullable bank_account_number_tail cannot be null');
        }
        $this->container['bank_account_number_tail'] = $bank_account_number_tail;

        return $this;
    }

    /**
     * Gets bank_account_holder_status.
     */
    public function getBankAccountHolderStatus(): ?string
    {
        return $this->container['bank_account_holder_status'];
    }

    /**
     * Sets bank_account_holder_status.
     *
     * @param null|string $bank_account_holder_status bank_account_holder_status
     */
    public function setBankAccountHolderStatus(?string $bank_account_holder_status): self
    {
        if (is_null($bank_account_holder_status)) {
            array_push($this->openAPINullablesSetToNull, 'bank_account_holder_status');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('bank_account_holder_status', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['bank_account_holder_status'] = $bank_account_holder_status;

        return $this;
    }

    /**
     * Returns true if offset exists. False otherwise.
     *
     * @param int $offset Offset
     */
    public function offsetExists($offset): bool
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     *
     * @param int $offset Offset
     *
     * @return null|mixed
     */
    #[\ReturnTypeWillChange]
    public function offsetGet($offset): mixed
    {
        return $this->container[$offset] ?? null;
    }

    /**
     * Sets value based on offset.
     *
     * @param null|int $offset Offset
     * @param mixed    $value  Value to be set
     */
    public function offsetSet($offset, mixed $value): void
    {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }

    /**
     * Unsets offset.
     *
     * @param int $offset Offset
     */
    public function offsetUnset($offset): void
    {
        unset($this->container[$offset]);
    }

    /**
     * Serializes the object to a value that can be serialized natively by json_encode().
     *
     * @see https://www.php.net/manual/en/jsonserializable.jsonserialize.php
     *
     * @return mixed returns data which can be serialized by json_encode(), which is a value
     *               of any type other than a resource
     */
    #[\ReturnTypeWillChange]
    public function jsonSerialize(): mixed
    {
        return ObjectSerializer::sanitizeForSerialization($this);
    }

    /**
     * Gets a header-safe presentation of the object.
     */
    public function toHeaderValue(): string
    {
        return json_encode(ObjectSerializer::sanitizeForSerialization($this));
    }

    /**
     * Array of nullable properties.
     */
    protected static function openAPINullables(): array
    {
        return self::$openAPINullables;
    }

    /**
     * Array of nullable field names deliberately set to null.
     *
     * @return bool[]
     */
    private function getOpenAPINullablesSetToNull(): array
    {
        return $this->openAPINullablesSetToNull;
    }

    /**
     * Setter - Array of nullable field names deliberately set to null.
     *
     * @param bool[] $openAPINullablesSetToNull
     */
    private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
    {
        $this->openAPINullablesSetToNull = $openAPINullablesSetToNull;
    }

    /**
     * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
     * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
     * $this->openAPINullablesSetToNull array.
     *
     * @param mixed $defaultValue
     */
    private function setIfExists(string $variableName, array $fields, $defaultValue): void
    {
        if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
            $this->openAPINullablesSetToNull[] = $variableName;
        }

        $this->container[$variableName] = $fields[$variableName] ?? $defaultValue;
    }
}
